package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ItemDesc;
import com.ruoyi.system.service.IItemDescService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品详情Controller
 *
 * @author ruoyi
 * @date 2022-04-24
 */
@RestController
@RequestMapping("/system/desc")
public class ItemDescController extends BaseController
{
    @Autowired
    private IItemDescService itemDescService;

    /**
     * 查询商品详情列表
     */
    @PreAuthorize("@ss.hasPermi('system:desc:list')")
    @GetMapping("/list")
    public TableDataInfo list(ItemDesc itemDesc)
    {
        startPage();
        List<ItemDesc> list = itemDescService.selectItemDescList(itemDesc);
        return getDataTable(list);
    }

    /**
     * 导出商品详情列表
     */
    @PreAuthorize("@ss.hasPermi('system:desc:export')")
    @Log(title = "商品详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ItemDesc itemDesc)
    {
        List<ItemDesc> list = itemDescService.selectItemDescList(itemDesc);
        ExcelUtil<ItemDesc> util = new ExcelUtil<ItemDesc>(ItemDesc.class);
        util.exportExcel(response, list, "商品详情数据");
    }

    /**
     * 获取商品详情详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:desc:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(itemDescService.selectItemDescById(id));
    }

    /**
     * 新增商品详情
     */
    @PreAuthorize("@ss.hasPermi('system:desc:add')")
    @Log(title = "商品详情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ItemDesc itemDesc)
    {
        return toAjax(itemDescService.insertItemDesc(itemDesc));
    }

    /**
     * 修改商品详情
     */
    @PreAuthorize("@ss.hasPermi('system:desc:edit')")
    @Log(title = "商品详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ItemDesc itemDesc)
    {
        return toAjax(itemDescService.updateItemDesc(itemDesc));
    }

    /**
     * 删除商品详情
     */
    @PreAuthorize("@ss.hasPermi('system:desc:remove')")
    @Log(title = "商品详情", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(itemDescService.deleteItemDescByIds(ids));
    }
}
